package com.example.hospitalsystem.controller;

import com.example.hospitalsystem.mapper.PatientMapper;
import com.example.hospitalsystem.pojo.dto.buylog.LogPageQueryDto;
import com.example.hospitalsystem.pojo.dto.patient.AddPatientDto;
import com.example.hospitalsystem.pojo.dto.patient.ChangePatientDto;
import com.example.hospitalsystem.pojo.dto.patient.PatientPageQueryDto;
import com.example.hospitalsystem.pojo.entity.BuyMedicineLog;
import com.example.hospitalsystem.pojo.entity.Department;
import com.example.hospitalsystem.pojo.entity.Patient;
import com.example.hospitalsystem.pojo.entity.PrescriptionPharmacy;
import com.example.hospitalsystem.pojo.vo.PatientItemVO;
import com.example.hospitalsystem.pojo.vo.PatientPrescriptionPharmacyVO;
import com.example.hospitalsystem.result.Result;
import com.example.hospitalsystem.service.PatientService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/patient")
@Tag(name="5.患者模块")
public class PatientController {

    @Autowired
    private PatientService patientService;

    @Operation(summary = "患者获取所开药品", security = {@SecurityRequirement(name = "Authorization")})
    @GetMapping("/pharmacy")
    public Result<Object> getPharmacy(){
        List<PrescriptionPharmacy> pp = patientService.getPharmacyByPatient();
        return Result.ok(pp);
    }

    @Operation(summary = "返回患者列表",security = {@SecurityRequirement(name = "Authorization")})
    @GetMapping("/patientItem")
    public Result<List<PatientItemVO>> getPatientItem(Integer patientId) {
        List<PatientItemVO> patientItem = patientService.getPatientItem(patientId);
        return Result.ok(patientItem);
    }

    @Operation(summary = "患者完善个人信息",security = {@SecurityRequirement(name = "Authorization")})
    @PostMapping("/addPatientInfo")
    public Result<Object> addPatientInfo(@RequestBody Patient patient){
        return patientService.addPatientInfo(patient);
    }
    @Operation(summary = "患者支付药品费用",security = {@SecurityRequirement(name = "Authorization")})
    @GetMapping("/paymentAmount/{id}")
    public Result<Object> paymentAmountByPatient(@PathVariable("id") Integer patientId) {
        return patientService.paymentAmountByPatient(patientId);
    }

    @Operation(summary = "患者获取个人信息",security = {@SecurityRequirement(name = "Authorization")})
    @GetMapping("/patientInfo")
    public Result<Object> getPatientInfo() {
        return patientService.getPatientInfo();
    }

    @Operation(summary = "用户-患者获取个人信息",security = {@SecurityRequirement(name = "Authorization")})
    @GetMapping("/user-patientInfo")
    public Result<Object> getUserPatientInfo() {
        return patientService.getUserPatientInfo();
    }

    @Operation(summary = "患者修改自己信息",security = {@SecurityRequirement(name = "Authorization")})
    @PostMapping("/changePatientInfo")
    public Result<Object> changePatientInfo(@RequestBody ChangePatientDto changePatientDto){
        return patientService.changePatientInfo(changePatientDto);
    }


    @Operation(summary = "患者注销信息",security = {@SecurityRequirement(name = "Authorization")})
    @DeleteMapping("/deletePatient/{password}")
    public Result<Object> deletePatient(@PathVariable("password") String password){
        return patientService.deletePatientInfo(password);
    }

    @Operation(summary = "管理员获取患者患者信息",security = {@SecurityRequirement(name = "Authorization")})
    @PostMapping("/getAlllPatientInfo")
    public Result<Object> getAllPatientInfo(@RequestBody PatientPageQueryDto patientPageQueryDto){
        return patientService.getAllPatientInfo(patientPageQueryDto);
    }

    @Operation(summary = "搜索患者", security = {@SecurityRequirement(name = "Authorization")})
    @GetMapping("/search")
    public Result<Object> searchPatient(String key){
        List<Patient> list = patientService.searchPatient(key);
        return Result.ok(list);
    }

    @Operation(summary = "删除购买记录信息", security = {@SecurityRequirement(name = "Authorization")})
    @DeleteMapping("/deleteLog/{id}")
    public Result<Object> deleteLog(@PathVariable("id") int id){
        return patientService.deleteLog(id);
    }

    @Operation(summary = "购买药品记录", security = {@SecurityRequirement(name = "Authorization")})
    @PostMapping("/log")
    public Result<Object> getAllLog(@RequestBody LogPageQueryDto logPageQueryDto){
        return patientService.getAllBuyLog(logPageQueryDto);

    }

    @Operation(summary = "搜索购买记录", security = {@SecurityRequirement(name = "Authorization")})
    @GetMapping("/searchLog")
    public Result<Object> searchLog(String key){
        List<BuyMedicineLog> list = patientService.searchLog(key);
        return Result.ok(list);
    }
}
